// ES5 作用域

var callbacks = [];
for(var i=0;i<=2;i++){
    callbacks[i] = function(){
        return i*2;
    }
}

console.table([
    callbacks[0](),
    callbacks[1](),
    callbacks[2]()
]);


// ES6

var callbacks2 = [];
for(let i=0;i<=2;i++){
    callbacks2[i] = function(){
        return i*2;
    }
}

console.table([
    callbacks2[0](),
    callbacks2[1](),
    callbacks2[2]()
]);


// ES5 立即执行函数
;(function(){
    var foo = function(){
        return 1;
    }
    console.log('foo()====1', foo() === 1)

    !(function(){
        const foo = function(){
            return 2;
        }
        console.log("foo === 2", foo() === 2);
    })()

})()

//ES6 立即执行函数
{
    function foo(){
        return 1;
    }
    console.log("foo() === 1", foo() === 1);

    {
        function foo(){
            return 2;
        }
        console.log("foo() === 2", foo() === 2);
        
    }
}